package com.lhl.fw.core.data.converter;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.AttributeConverter;
import java.util.Map;

/**
 * @className: HashMapConverter
 * @description: 数据库字段json化
 * @author: king
 * @date: 2020-09-03 12:06
 **/
@Slf4j
public class HashMapConverter implements AttributeConverter<Map<String, Object>, String> {
    @Override
    public String convertToDatabaseColumn(Map<String, Object> stringObjectMap) {
        log.debug("attribute=={}", stringObjectMap);
        return JSONUtil.toJsonStr(stringObjectMap);
    }

    @Override
    public Map<String, Object> convertToEntityAttribute(String s) {
        log.debug("dbData=={}", s);
        return JSONUtil.toBean(s, Map.class);
    }
}
